using UnityEngine;
using System.Collections;/*
 * This for object you can drop teims from the inventory
 * This script 
 * 1. hold object info 
 * 2. flashes the object on mouse hover, when wrong or the correct object is hovered
 * 3. invokes the global inventory method to remove and save the object.
 * */


public class PropItem : MonoBehaviour {

    public string propName = "Put your Object name";
    public string propTag = "add the database key tag here";
    public Inventory inventory; //reference to our inventory
    public SceneMgr myscene;  // reference to the level's scene mgr object.
    public GUIText prompter;


	// Use this for initialization
	void Start () {
	
	}
    void OnMouseOver()
    {
        //  determine if there is object in hand
        if (inventory.GetComponent<Inventory>().IsItemPickedUp())
        {

            string itemTag = inventory.GetComponent<Inventory>().GetItemPickedUp().GetComponent<InventoryItem>().itemTag;
            //print(itemTag);
            // determine if it is the correct or relevant object
            string curTargetPropTag = myscene.GetComponent<SceneMgr>().GetMatch(itemTag);
            if (curTargetPropTag == propTag)
            {
                prompter.text= "good compare";
                // catch button up , as a drop
                if (Input.GetMouseButtonUp(0))
                {
                    // update the prop state
                    prompter.text= "correct matched!";
                    // notify success
                    myscene.GetComponent<SceneMgr>().Score += 10;
                     
                }
            }
            else
            {
                // else show cursor for inapplicable cursor
                prompter.text= "bad compare";
            }
        }
    }

    void OnMouseExit()
    {

        // restore cursor to oroginal state 
        // restore prop object alpha to 1
        Color curcolor = renderer.material.color;
        curcolor.a = 1;
        renderer.material.color = curcolor;
        prompter.text = "";
    } 
}
